package com.tanhua.dubbo.api.db;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.tanhua.domain.db.BlackList;
import com.tanhua.domain.db.UserInfo;
import com.tanhua.dubbo.mapper.BlackListMapper;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;

@Service
public class BlackListApiImpl implements BlackListApi {

    @Autowired
    private BlackListMapper blackListMapper;

    @Override
    public IPage<UserInfo> blacklistByUserId(Integer page, Integer pagesize,Long userId) {
        Page<UserInfo> page1 = new Page<>(page,pagesize);
//        SELECT u.* FROM tb_black_list b  INNER JOIN tb_user_info u  ON b.black_user_id=u.id AND b.user_id=136
//        SELECT u.* FROM tb_black_list b  , tb_user_info u  WHERE b.black_user_id=u.id AND b.user_id=136
        IPage<UserInfo> iPage = blackListMapper.blacklistByUserId(page1,userId);
        return iPage;
    }

    @Override
    public void delBlacklist(Long userId, Long blackListId) {
        QueryWrapper<BlackList> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda().eq(BlackList::getUserId,userId);
        queryWrapper.lambda().eq(BlackList::getBlackUserId,blackListId);
        blackListMapper.delete(queryWrapper);
    }
}
